package com.va1m.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.va1m.demo.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author Admin
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 更新用户记录 只在余额充足时才能成功更新
     * @param userId
     * @param amount
     * @param expireDate
     * @return
     */
    @Update("update t_user set " +
            "balance = balance - #{amount} ," +
            " expire_date = #{expireDate} " +
            "where user_id = #{userId} and balance > #{amount}")
    public Integer updateUserInfo(@Param(value = "userId") Integer userId,
                   @Param(value = "amount")BigDecimal amount,
                   @Param(value = "expireDate") Date expireDate);
}
